package net.worldscale.xp.wslib.urm;

import java.util.Hashtable;

class ImplSandbox extends Sandbox {

	private final ImplResource mMainRes;
	private final Hashtable<String, ImplResource> mResources;
	private ISandboxListener mListener;

	public ImplSandbox(String uri) {
		mMainRes = new ImplResource(uri, this);
		mResources = new Hashtable<String, ImplResource>();
		//
		this.mResources.put(uri, this.mMainRes);
	}

	@Override
	public Resource getResource(String uri) {
		return mResources.get(uri);
	}

	@Override
	public Resource openResource(String uri) {
		final Resource res = getResource(uri);
		if (res == null) {
			final ImplResource newRes = new ImplResource(uri, this);
			this.mResources.put(uri, newRes);
			return newRes;
		}
		return res;
	}

	@Override
	public Resource getMainResource() {
		return this.mMainRes;
	}

	@Override
	public void setListener(ISandboxListener l) {
		this.mListener = l;
	}

	@Override
	public ISandboxListener getListener() {
		return this.mListener;
	}
}
